package accs.gui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import accs.product.update.Version;
import net.miginfocom.swing.MigLayout;

public class AboutDialog extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JLabel versionLabel;

	/**
	 * Create the dialog.
	 */
	public AboutDialog(JFrame owner) {
		super(owner);
		setResizable(false);
		setModal(true);
		setTitle("About AccountChecker");
		setSize(450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new BorderLayout(0, 0));
		{
			JPanel panel = new JPanel();
			contentPanel.add(panel, BorderLayout.SOUTH);
			panel.setLayout(new MigLayout("", "[79px][16px]", "[14px][]"));
			{
				JLabel lblNewLabel = new JLabel("Hermes-Version:");
				panel.add(lblNewLabel, "cell 0 0,alignx left,aligny top");
			}
			{
				versionLabel = new JLabel(Version.CURRENT_VERSION.toString());
				panel.add(versionLabel, "cell 1 0,alignx left,aligny top");
			}
			{
				JLabel lblNewLabel_2 = new JLabel("Java-Version:");
				panel.add(lblNewLabel_2, "cell 0 1");
			}
			{
				String javaVersion=System.getProperty("java.version");
				JLabel javaVersionLabel = new JLabel(javaVersion==null ? "?" : javaVersion);
				panel.add(javaVersionLabel, "cell 1 1");
			}
		}
		{
			JLabel lblNewLabel_1 = new JLabel("");
			lblNewLabel_1.setIcon(new ImageIcon(AboutDialog.class.getResource("/accs/gui/img/about.png")));
			contentPanel.add(lblNewLabel_1, BorderLayout.CENTER);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						dispose();
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
		}
		pack();
		setLocationRelativeTo(owner);
	}

//	private void checkUpdate() {
//		try {
//			Version newVersion=new Updater().checkForUpdate();
//			String message="";
//			
//			if(newVersion==null) {
//				message="You already have the newest version: "+Version.CURRENT_VERSION.toString();
//			} else {
//				message="A new version is available: "+newVersion;
//			}
//			
//			JOptionPane.showMessageDialog(this,message,"Update-Info",JOptionPane.INFORMATION_MESSAGE);
//		} catch (Exception e) {
//			JOptionPane.showMessageDialog(this,e.toString(),"Update-Error",JOptionPane.ERROR_MESSAGE);
//		}
//	}
}